package com.banhujiu.spider.youku;

import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

/**
 * @author banhujiu
 * @date 2018/8/5 0005 14:38
 */
public class Bootstrap {
	public static void main(String[] args) throws IOException {
		String url = "http://i.youku.com/i/UMzQwOTk4NDIw/videos?spm=a2hzp.8244740.0.0";
		Document parse = Jsoup.parse(new URL(url).openStream(), "utf-8", url);
		Elements elements = parse.select("div.v-link a");
		List<String> urlList = new ArrayList<>();
		for (Element element : elements) {
			urlList.add("http:" + element.attr("href"));
		}

		while (parse.select("li.next a").size() > 0) {
			String nextUrl = "http://i.youku.com" + parse.select("li.next a").first().attr("href");
			parse = Jsoup.parse(new URL(nextUrl).openStream(), "utf-8", nextUrl);
			elements = parse.select("div.v-link a");
			for (Element element : elements) {
				urlList.add("http:" + element.attr("href"));
			}
		}

		for (String s : urlList) {
			System.out.println(s);
		}
	}
}
